<%- include("components/header",{type:''}) %>

<div id="fh5co-page">
	<div id="fh5co-main">
		<div class="container">
            <div class="starter-template">
                <form class="form-horizontal" method="post">
                    <div class="form-group">
                        <label for="inputTitle" class="col-sm-2 control-label">标题</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" name="title" id="title" value="<%- postsTitle %>">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="inputContent" class="col-sm-2 control-label">内容</label>
                        <div class="col-sm-10">
                            <textarea id="summernote" name="content"><%= postsContent %></textarea>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-offset-2 col-sm-10">
                            <button type="submit" id="submit" class="btn btn-default">修改</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
	</div>
</div>



<script>
    $(function(){
        $('#summernote').summernote({
            tabsize: 2,
            height: 200,
        });
        $('#submit').click(()=>{
            $.ajax({
                url: '/posts/<%= postsId %>/edit',
                data: $('.form').serialize(),
                type: "POST",
                cache: false,
                dataType: 'json',
                success: function (res) {
                    if (res) {
                        fade('修改成功')
                        setTimeout(()=>{
                            window.location.href = "/posts/<%= postsId %>"
                        },1000)
                    }
                },
                error: function () {
                    console.log('异常');
                }
            })		
        })
    })
</script>

<%- include("components/footer") %>